package com.lvmama.core.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lvmama.core.bean.UserTravelDetail;
import com.lvmama.core.bean.UserTravelDetailDTO;
import com.lvmama.core.bean.base.BaseResponse;
import com.lvmama.core.bean.base.ResultBase;
import com.lvmama.core.service.UserTravelService;
import com.lvmama.enums.ErrorCodeEnum;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("/userTravel")
public class UserTravelController {
    @Reference(version = "1.0.0", timeout = 30000)
    private UserTravelService userTravelService;

    /**
     * 查询用户travel details
     * 
     * @param id
     * @return
     */
    @RequestMapping("/detail")
    @ResponseBody
    public BaseResponse<List<UserTravelDetail>> selectUserTravelDetail(@RequestBody UserTravelDetailDTO query) {
        log.info("request selectUserTravelDetail start.");
        BaseResponse<List<UserTravelDetail>> resp = new BaseResponse<>();
        try {
            ResultBase<List<UserTravelDetail>> result = userTravelService.selectUserTravelDetailByQuery(query);
            resp.setCode(result.getErrorCode());
            resp.setMsg(result.getErrorMsg());
            if (result.isSuccess() && !result.getValue().isEmpty()) {
                resp.setSuccess(result.isSuccess());
                resp.setData(result.getValue());
            }
        } catch (Exception e) {
            log.error("selectUserTravelDetail Exception:{}", e.getMessage(), e);
            resp.setMsg(ErrorCodeEnum.UNKOWN_ERROR.getMsg());
        }
        log.info("request selectUserTravelDetail end.");
        return resp;
    }

}
